<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\index\controller;

use app\common\lib\Util;
use app\common\lib\Redis;

/**
 * Description of Admin
 *
 * @author tang
 */
class Admin {
    /**
     * 上传图片
     */
    public function uploadImg() {
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move( '../public/static/upload');
        if($info){
            // 成功上传后 获取上传信息
            return Util::show(config('code.success'), '上传成功',['img_url'=>'/upload/'.$info->getSaveName()]);
        }else{
            // 上传失败获取错误信息
            echo $file->getError();
        }
    }
    /**
     * 推送消息
     */
    public function push() {
        //入库
        //推送
        try {
            $client = Redis::getInstance()->sMembers(config('redis.live_push'));
            foreach ($client as $fd) {
                $_POST['http_server']->push($fd,'hello');
            }
        } catch (Exception $exc) {
            echo $exc->getTraceAsString();
        }
        
    }
}
